// RemoveDualityOperLeftRecursion.h: interface for the RemoveDualityOperLeftRecursion class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_REMOVEDUALITYOPERLEFTRECURSION_H__33FCE860_0945_44A6_88CC_8935271D5F96__INCLUDED_)
#define AFX_REMOVEDUALITYOPERLEFTRECURSION_H__33FCE860_0945_44A6_88CC_8935271D5F96__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "RemoveLeftRecursion.h"

class RemoveDualityOperLeftRecursion : public RemoveLeftRecursion  
{
public:
	RemoveDualityOperLeftRecursion();
	virtual ~RemoveDualityOperLeftRecursion();

public:
	ComplierNote* Operator(){
		return m_pOper;
	}

	ComplierNote* Note(){
		return m_pNote;
	}

public:
	void Operator(ComplierNote* pOper){
		m_pOper = pOper;
	}

	void Note(ComplierNote* pNote){
		m_pNote = pNote;
	}

public:
	ComplierNote* m_pOper;
	ComplierNote* m_pNote;
};

template<class Oper, class Note, class _Note> BOOL _DualityOperIterpret(_Note* p_Note, ComplierNote* pParent, RemoveDualityOperLeftRecursion* pOper, INT nNum, ...)
{
	ASSERT(pOper);
	ASSERT(pParent);
	Note* pNote = NULL;
	_Note* pNext = NULL;
	Oper* pOperNote = NULL;

	pOperNote = new Oper;
	pOperNote->SetOwner(pParent);
	if(!pOperNote->Interpret())
	{
		delete pOperNote;
		pParent->ErrorInfo(pOperNote->ErrorInfo());
		return FALSE;
	}
	pOper->Operator(pOperNote);

	pNote = new Note;
	pNote->SetOwner(pParent);
	if(!pNote->Interpret())
	{
		pParent->ErrorInfo(pNote->ErrorInfo());
		delete pNote;
		return FALSE;
	}
	pOper->Note(pNote);

	CString strTemp;
	CString strCondition;
	BOOL bRun = FALSE;
	strTemp = pOper->AAnalyzer()->GetCurSymbol();
	va_list list;
	va_start(list, nNum);
	for(int i = 0; i < nNum; i++)
	{
		strCondition = va_arg(list, CString);
		if(strTemp == strCondition)
		{
			bRun = TRUE;
			break;
		}
	}
	if(bRun)
	{
		pNext = new _Note;
		pNext->Parent(pParent);
		pNext->AAnalyzer(pOper->AAnalyzer());
		pNext->EReporter(pOper->EReporter());
		pOper->Next(pNext);
		return pNext->Interpret();
	}

	return TRUE;
}
#endif // !defined(AFX_REMOVEDUALITYOPERLEFTRECURSION_H__33FCE860_0945_44A6_88CC_8935271D5F96__INCLUDED_)
